

define(['common/controllers', 'domReady'],
    function (controllers, domReady) {
        controllers.controller('withdrawCtrl',function ($scope,$location,$state,$cacheFactory,withdrawService) {
            $scope.params = {
                size:5,
                page:1
            }
            $scope.currentPage = 1;
            $scope.withdrawList = [];
            $scope.point=[];
            $scope.pages = [];
            var load = function(params){

                params.page =$scope.currentPage;
                withdrawService.getWithdrawList(params,function(err,data){
                    if(err){
                        console.log(err);
                        return false;
                    }
                    $scope.withdrawList = data.results;

                    $scope.count = data.counts;
                    console.log(data);
                    //分页后的订单
                    $scope.numPages = data.counts>0?Math.ceil(data.counts / params.size):1;
                    $scope.pageStart = data.counts>0?($scope.currentPage - 1) * params.size + 1:0;
                    $scope.pageEnd = params.size * $scope.currentPage > data.counts ? data.counts : $scope.currentPage * params.size;




                })
            }

            load($scope.params);

            // 翻页
            $scope.onSelectPage = function (page) {
                $scope.currentPage = page;
                //$scope.params.page = page;

                load($scope.params);
            };

            $scope.judge=function(page,index){
                if(Math.abs($scope.currentPage - page)==5&&page!=1&&page!=$scope.numPages){
                    $scope.point[index]=true;
                }else{
                    $scope.point[index]=false;
                }

                if(Math.abs($scope.currentPage - page)<=5||page==$scope.numPages||page==1){
                    return true;
                }else{
                    return false;
                }
            }

            $scope.confirmWithdraw = function(withdrawId,withdrawOrderNo,userId,money){
                var c = confirm("此操作不可逆转，您确认要继续吗?");
                if(c){
                    withdrawService.confirmWithdraw(withdrawId,withdrawOrderNo,userId,money,function(err,data){
                        if(err){
                            return err;
                        }
                        load($scope.params);

                    });
                }else{
                    console.log("取消");
                }

            }


        })

    });

